package com.example.server.controller;

import com.example.server.domain.Dormadmin;
import com.example.server.domain.Dormchange;
import com.example.server.service.DormadminService;
import com.example.server.service.DormchangeService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//@CrossOrigin(origins = "*",allowCredentials = "true",allowedHeaders = "*",methods = {RequestMethod.GET,RequestMethod.POST,RequestMethod.DELETE,RequestMethod.PUT,RequestMethod.OPTIONS})
@Controller
@RequestMapping("/dormchange")
public class DormchangeController {
    private final DormchangeService dormchangeService;

    public DormchangeController(DormchangeService dormchangeService) {
        this.dormchangeService = dormchangeService;
    }



    @RequestMapping("/create")
    @ResponseBody
    public void createDormchange(@RequestBody Dormchange dormadmin) {
        dormadmin.setAprovestatus("未审批");
        dormchangeService.createDormchange(dormadmin);
    }
    @RequestMapping("/delete")
    @ResponseBody
    public void deleteDormchange(Long id) {
        dormchangeService.deleteDormchange(id);
    }
    @RequestMapping("/querybyid")
    @ResponseBody
    public Dormchange getDormchangeById(Long id) {
        return dormchangeService.getDormchangeById(id);
    }


    @RequestMapping("/pass")
    @ResponseBody
    public void approvePass(Long id) {
         dormchangeService.approvePass(id);
    }

    @RequestMapping("/reject")
    @ResponseBody
    public void approveReject(Long id) {
         dormchangeService.approveReject(id);
    }
    @RequestMapping("/update")
    @ResponseBody
    public void updateDormchange(@RequestBody Dormchange dormadmin) {
        dormchangeService.updateDormchange(dormadmin);
    }
    @RequestMapping("/queryall")
    @ResponseBody
    public List<Dormchange> getAllDormchange() {
        return dormchangeService.getAllDormchange();
    }
    @RequestMapping("/querylike")
    @ResponseBody
    public List<Dormchange> querylike(String sname) {
        return dormchangeService.querylike(sname);
    }
}
